/*
** env.c for mysh in /home/nadali_t//local/svn/tek2ed/minishell1
** 
** Made by thomas nadalie
** Login   <nadali_t@epitech.net>
** 
** Started on  Thu Nov  8 12:24:01 2012 thomas nadalie
** Last update Thu Nov  8 12:24:36 2012 thomas nadalie
*/

#include	<stdlib.h>
#include	"my.h"

char		**my_env(char **env)
{
  char		**new_env;
  int		i;

  i = 0;
  if ((new_env = malloc(sizeof(*new_env) * (my_tablen(env) + 1))) == NULL)
    return (env);
  while (env[i])
    {
      if ((new_env[i] = malloc(sizeof(**new_env) * my_strlen(env[i]) + 1)) == NULL)
	return (NULL);
      new_env[i] = my_strcpy(new_env[i], env[i]);
      i++;
    }
  return (new_env);
}

char		**my_setenv(char **env, char *param, t_list *list)
{
  char		**new_env;
  int		i;

  i = 0;
  if ((new_env = malloc(sizeof(*new_env) * (my_tablen(env) + 2))) == NULL)
    return (env);
  while (env[i])
    {
      if ((new_env[i] = malloc(sizeof(env[i]) * my_strlen(env[i]))) == NULL)
	return (NULL);
      new_env[i] = my_strcpy(new_env[i], env[i]);
      i++;
    }
  new_env[i++] = my_strdup(param);
  new_env[i] = NULL;
  list->stop = 1;
  return (new_env);
}

char		**my_unsetenv(char **env, char *param, t_list *list)
{
  char		**new_env;
  int		i;

  i = 0;
  if ((new_env = malloc(sizeof(*new_env) * (my_tablen(env) + 1))) == NULL)
    return (env);
  while (env[i])
    {
      if ((new_env[i] = malloc(sizeof(char*) * my_strlen(env[i]))) == NULL)
	return (NULL);
      new_env[i] = my_strcpy(new_env[i], env[i]);
      i++;
    }
  i = 0;
  while ((find_path(new_env[i], param)) == 1)
    i++;
  while (new_env[i] != NULL)
    {
      new_env[i] = new_env[i + 1];
      i++;
    }
  new_env[i] = NULL;
  list->stop = 1;
  return (new_env);
}
